package com.ebelter.temperature.activitys;


import android.annotation.SuppressLint;
import android.app.Dialog;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import com.ebelter.btcomlib.bases.activity.BaseActivity;
import com.ebelter.btcomlib.models.bluetooth.products.temperature.TemperatureManager;
import com.ebelter.btcomlib.utils.StatusBarUtil;
import com.ebelter.btcomlib.utils.StringUtils;
import com.ebelter.btcomlib.views.dialogs.TextTipDialog;
import com.ebelter.temperature.R;

public class T_DeviceManagerActivity extends BaseActivity {

    //private static final String TAG="T_DeviceManagerActivity";

    public static final int REQUEST_CODE = 121;


    TextView topTitleTv;
    TextView item_band_tv;

    private TemperatureManager mTemperatureManager;


    @Override
    protected int loadLayoutById() {
        return R.layout.activity_t_devicemaneger;
    }
    @Override
    protected void initView() {
        StatusBarUtil.setColor(this, Color.parseColor("#787ede"));
        FV();
    }

    private void FV() {
        topTitleTv=findViewById(R.id.top_title_tv);
        item_band_tv=findViewById(R.id.item_band_tv);

    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void initData() {
        topTitleTv.setText(R.string.device_management);
        mTemperatureManager=new TemperatureManager(this);
        item_band_tv.setText(mTemperatureManager.getBondDeviceName()+"("+mTemperatureManager.getBondDeviceAddress()+")");
    }

    //解绑设备
    public void unpairClick(View view){
        TextTipDialog textTipDialog=new TextTipDialog(this, StringUtils.getResStr(R.string.device_management_remove_tip));
        textTipDialog.setListener(new TextTipDialog.ICancelOkBtListener() {
            @Override
            public void cancel(Dialog dialogView) {
                dialogView.cancel();
            }

            @Override
            public void ok(Dialog dialogView) {
                dialogView.cancel();
                mTemperatureManager.setBondDeviceAddress(null);
                mTemperatureManager.setBondDeviceName(null);
                setResult(1);
                finish();//直接退出
            }
        });
        textTipDialog.show();

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mTemperatureManager!=null){
            mTemperatureManager.exit();
            mTemperatureManager = null;
        }
    }


    public void backClick(View view){
        finish();
    }
}
